/**
 * 
 */
package com.effectiv.srvlet.web;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * @author edhrkay
 *
 */
public class FrontController extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		System.out.println("DO GET CALLED");
		process(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		System.out.println("DO POST CALLED");
		process(req, resp);
	}
	
	public void process(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String firstName = req.getParameter("firstName");
		String lastName = req.getParameter("lastName");
		String salary = req.getParameter("salary");
		Long lSalary = 0L;
		if(salary != null )
			lSalary = Long.parseLong(salary, 0);
		
		System.out.println(firstName);
		System.out.println(lastName);
		System.out.println(salary);
		System.out.println(lSalary);
		
		//map the request url to a controller method
		
		String url = req.getRequestURI();
		
		System.out.println(url);
		
		RequestDispatcher dispatcher = req.getRequestDispatcher(url);
		dispatcher.forward(req, resp);
	}

}
